<?
	include_once ("../include/conn.php");
	include_once ('config.php');
	
	/**************************************
	 * ************ 获取自定义区域列表 ***********
	 * ************************************/
	$results = array('code' => 0,'msg'=>'数据正常获取！','dataList'=>Array());//用于正常有数据输出的
	
	//开始数据处理
	$addr = $_GET['addr'];
	$addr_arr = explode(',', $addr);

	//先查询出发送过来的省市区数据
	$cmd_addr ="
		select 
		province.name province_name,
		province.provinceid province_id,
		city.name city_name,
		city.cityid city_id,
		area.name area_name,
		area.areaid area_id
		from province 
		left join(select * from city) city on city.provinceid = province.provinceid 
		left join(select * from area) area on area.cityid = city.cityid 
		where province.name = '{$addr_arr[0]}'
		and city.name='{$addr_arr[1]}' 
		and area.name='{$addr_arr[2]}'
	";
	
	$row_addr = $mydb->fetch_assoc($cmd_addr);
	$results['addrinfo'] = $row_addr;


	# 按小程序发送过来的省市区，查询对应的园区
	# 下面同时加入省市区的名字作为条件，是为了防止不同地区公司名相同的情况，但应该不会有这种情况 
	/*
	,area.name area_name 
	,area.areaid area_id 
	,city.name city_name 
	,city.cityid city_id 
	,province.name province_name 
	,province.provinceid province_id 
	*/
	$cmd = "
		select scope.* 
		
		from {$TABLE_C}vote_scope scope
		left join(select * from area) area on scope.areaid = area.areaid 
		left join(select * from city) city on area.cityid = city.cityid 
		left join(select * from province) province on province.provinceid = city.provinceid 
		where province.name='{$addr_arr[0]}' 
			and city.name='{$addr_arr[1]}' 
			and area.name='{$addr_arr[2]}'
	";
	$rs = mysql_query($cmd);

	// 遍历结果
	while ($row = mysql_fetch_assoc($rs)) {
		$results['dataList'][] = $row;
	}

	// //////////////////输出数据////////////////////////////////
	echo decodeUnicode(json_encode($results));
	mysql_close();
?>